package org.wkg.lesson07;

import java.util.concurrent.TimeUnit;

public class Demo_705 {



    public static void main(String[] args) {
        MyBlockingQueue02 queue = new MyBlockingQueue02(100);
        Thread producer = new Thread(() -> {
            int num = 0;
            while (true) {
                try {
                    queue.put(num);
                    System.out.println("生产了元素：" + num);
                    num++;
                    TimeUnit.MILLISECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        producer.start();


        Thread consumer = new Thread(() -> {
            while (true) {
                try {
                    System.out.println("消费了元素：" + queue.take());
                    TimeUnit.MILLISECONDS.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        consumer.start();
    }
}
